package com.zuthub.web.controller.system;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.zuthub.common.annotation.Log;
import com.zuthub.common.core.controller.BaseController;
import com.zuthub.common.core.domain.AjaxResult;
import com.zuthub.common.enums.BusinessType;
import com.zuthub.system.domain.SysMember;
import com.zuthub.system.service.ISysMemberService;
import com.zuthub.common.utils.poi.ExcelUtil;
import com.zuthub.common.core.page.TableDataInfo;

/**
 * 社员管理Controller
 * 
 * @author zuthub
 * @date 2021-04-01
 */
@RestController
@RequestMapping("/system/member")
public class SysMemberController extends BaseController
{
    @Autowired
    private ISysMemberService sysMemberService;

    /**
     * 查询社员管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:member:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysMember sysMember)
    {
        startPage();
        List<SysMember> list = sysMemberService.selectSysMemberList(sysMember);
        return getDataTable(list);
    }

    @GetMapping("/tourist")
    @CrossOrigin
    public TableDataInfo listForTourist(SysMember sysMember)
    {
        startPage();
        List<SysMember> list = sysMemberService.selectSysMemberList(sysMember);
        return getDataTable(list);
    }

    /**
     * 导出社员管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:member:export')")
    @Log(title = "社员管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(SysMember sysMember)
    {
        List<SysMember> list = sysMemberService.selectSysMemberList(sysMember);
        ExcelUtil<SysMember> util = new ExcelUtil<SysMember>(SysMember.class);
        return util.exportExcel(list, "member");
    }

    /**
     * 获取社员管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:member:query')")
    @GetMapping(value = "/{memberId}")
    public AjaxResult getInfo(@PathVariable("memberId") Long memberId)
    {
        return AjaxResult.success(sysMemberService.selectSysMemberById(memberId));
    }

    /**
     * 新增社员管理
     */
    @PreAuthorize("@ss.hasPermi('system:member:add')")
    @Log(title = "社员管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysMember sysMember)
    {
        return toAjax(sysMemberService.insertSysMember(sysMember));
    }

    /**
     * 修改社员管理
     */
    @PreAuthorize("@ss.hasPermi('system:member:edit')")
    @Log(title = "社员管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysMember sysMember)
    {
        return toAjax(sysMemberService.updateSysMember(sysMember));
    }

    /**
     * 删除社员管理
     */
    @PreAuthorize("@ss.hasPermi('system:member:remove')")
    @Log(title = "社员管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{memberIds}")
    public AjaxResult remove(@PathVariable Long[] memberIds)
    {
        return toAjax(sysMemberService.deleteSysMemberByIds(memberIds));
    }
}
